package library;

import java.util.Random;

public class CardStack {
	public Card[] cards;
	public CardStack()
	{
		cards = new Card[0];
	}
	public CardStack(String init)
	{
		setup(init);
	}
	public void setup(String init)
	{
		String[] cardStrings = init.trim().replaceAll(","," ").replaceAll("[\\s]+", " ").split(" ");
		cards = new Card[cardStrings.length];
		for (int i = 0; i < cards.length; i++) {
			cards[i] = new Card(cardStrings[i]);
		}
	}
	public void shuffle(){
		Random rgen = new Random();  // Random number generator
		for (int i = 0; i < cards.length; i++) {
			int randomPosition = rgen.nextInt(cards.length);
		    Card temp = cards[i];
		    cards[i] = cards[randomPosition];
		    cards[randomPosition] = temp;
		}
	}
	public Card draw(){
		Card temp = cards[0];
		remove(0);
		return temp;
	}
	public void remove(int position)
	{
		Card[] temp = new Card[cards.length-1];
		System.arraycopy(cards, 0, temp, 0, position);
		System.arraycopy(cards, position + 1, temp, position, cards.length-1-position);
		cards = temp;
	}
	public int size(){
		return cards.length;
	}
	public void print()
	{
		for (int i = 0; i < cards.length; i++) {
			System.out.println(cards[i].name);
		}
	}
}